package com.iflytek.pet.common.resp;

import com.iflytek.pet.common.constant.ApiResponseStatusEnum;
import lombok.Data;

/**
 * @author: JohnRambo
 * @description: TODO
 * @date: 2024/5/26 09:00
 * @version: 1.0
 */
@Data
public class ApiResponse<T> {

    /**
     * 返回值code
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;


    private ApiResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ApiResponse success(){
        return new ApiResponse<>(ApiResponseStatusEnum.SUCCESS.getCode(), ApiResponseStatusEnum.SUCCESS.getMsg(), null);
    }

    public static <T> ApiResponse success(T data){
        return new ApiResponse<>(ApiResponseStatusEnum.SUCCESS.getCode(), ApiResponseStatusEnum.SUCCESS.getMsg(), data);
    }

    public static <T> ApiResponse error(String msg){
        return new ApiResponse<>(ApiResponseStatusEnum.ERROR.getCode(), msg, null);
    }

    public static <T> ApiResponse error(ApiResponseStatusEnum statusEnum){
        return new ApiResponse<>(statusEnum.getCode(), statusEnum.getMsg(), null);
    }

}